package com.itheima.demo02.Exception;

import java.io.FileNotFoundException;
import java.io.IOException;

public class Demo01TryCatch {
    public static void main(String[] args) {
        try {
            readFile("d:\\a.tx");
        } catch (IOException e) {
//            System.out.println("catch---传递的文件后缀不是.txt");
            System.out.println(e.getMessage());
            System.out.println(e.toString());
            e.printStackTrace();
        }

    }

    public static void readFile(String fileName) throws IOException {
        if (!fileName.endsWith(".txt")) {
            throw new IOException("文件后缀名不对!");
        }
        System.out.println("路径没有问题,读取文件");
    }
}
